/*
 * @Author: your name
 * @Date: 2021-09-16 18:05:49
 * @LastEditTime: 2021-09-17 17:07:54
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \Briup\JS\Swiper\模板\js\lunbo.js
 */

var pic = $("#pic>li");
var num = $('#num>li');
console.log(num);
var btn_left = $("#btnl");
console.log(btn_left);
var btn_right = $('.btn_right');
var index = 0; //索引
var timer = 0; //定时器

//图片改变函数
function change(cuindex) {
    for (var i = 0; i < pic.length; i++) {
        pic[i].style.display = 'none';
        num[i].className = "";
    }
    pic[cuindex].style.display = 'block';
    num[cuindex].className = 'active';
    index = cuindex;
}

// 定时器函数
function run() {
    index++;
    if (index >= pic.length) {
        index = 0;
    }
    change(index);
}
timer = setInterval(run, 4000);

// 添加事件
btn_left.on('click', function() {
    index--;
    if (index > pic.length) {
        index = 0;
    }
    change(index);
})